﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductSKUBatchAdd.aspx.cs"
    Inherits="ZLCMS.Web.SystemManage.Basics.ProductSKU.ProductSKUBatchAdd" %>

<%@ Register TagPrefix="fc" TagName="JFileControl" Src="~/SystemManage/Control/JFileControl.ascx " %>
<%@ Register TagPrefix="ddt" TagName="DropDownTreeControl" Src="~/SystemManage/Control/ddt/DropDownTreeControl.ascx " %>
<%@ Register Src="~/SystemManage/Control/SinglePictureControl.ascx" TagName="SinglePictureControl"
    TagPrefix="spc" %>
<%@ Register Src="/SystemManage/Control/CheckBoxControl/CheckBoxControl.ascx" TagName="CheckBoxControl"
    TagPrefix="uc1" %>
<form id="Form1" method="post" runat="Server" class="pageForm required-validate"
onsubmit="return validateCallback(this, dialogAjaxDone);" action="/SystemManage/Basics/ProductSKU/ProductSKUBatchAdd.aspx">
<!-- 需保存的全局变量 -->
<asp:label runat="server" id="_id" visible="False"></asp:label>
<div class="pageContent">
    <input type="hidden" name="cid" id="cid" runat="server" />
    <div class="pageFormContent" layouth="56">
        <dl style="display:none">
            <dt>SKU商品名称：</dt>
            <dd>
                <asp:textbox runat="server" id="tb_name" width="200px"></asp:textbox>
                （建议10个汉字以内）
            </dd>
        </dl>
         <dl class="nowrap">
            <dt>定制属性：</dt>
            </dl>
        <dl class="nowrap">
            <dt></dt>
            <dd >
            <% if (grid.Items.Count == 0)
               { %>
                <fieldset >
                         &nbsp;&nbsp;   暂无
                        </fieldset>
            <% } %>
                <asp:repeater id="grid" runat="server">
                    <ItemTemplate>
                        <fieldset name="fieldset_sku" skugroupid="<%# Eval("Id") %>"    >
                            <legend >
                            <%#Eval("SkuName") %>
                            </legend>
                            <div class="checklist" name="div_items">
                                <%#ShowCheckbox(Eval("Id"))%>
                            </div>
                        </fieldset>
                    </ItemTemplate>
                </asp:repeater>
            </dd>
        </dl>
      
      <h2 class="contentTitle">sku产品信息</h2>
      <div class="divider"></div>
        <table class="list"  width="">
            <thead>
                <tr>
                  <%= GetSkuGroupHtml() %>
                     <th>
                        市场价
                    </th>
                    <th >
                        销售价
                    </th>
                    <th >
                        数量
                    </th>   
                     <th >
                        内部编码
                    </th>
                  <%--  <th >
                        操作
                    </th>--%>
                </tr>
            </thead>
            <tbody>
                 <asp:repeater runat="server" id="rpt_sku_product">
                     <ItemTemplate>
 <tr target="uid" rel='ff' <%# Eval("IsShow") as string=="1"?"":"style='display:none;'" %> name="skuproduct" skuproductid="<%#Eval("Id") %>">

				    <%# GetSkuItemHtml(Eval("ParamCode").ToString()) %> 
				    <td><input name="txt_market_price" type="text" class="number" value="<%#Eval("MarketPrice") %>" /></td>
                        <td><input name="txt_sale_price" class="number"     type="text" value="<%#Eval("SalePrice") %>" /></td>
				    <td><input name="txt_storage_price" class="digits" min="0"   type="text" value="<%#Eval("Storage") %>" /></td>
                     <td><input name="txt_interior_code"    type="text" value="<%#Eval("InteriorCode") %>" /></td>
				 <%--   <td>操作</td>--%>
			    </tr>
                     </ItemTemplate>
                    </asp:repeater>
                <asp:hiddenfield runat="server" id="hid_sku_pro_jsonStr"></asp:hiddenfield>
                <asp:hiddenfield runat="server" id="hid_product_sku"></asp:hiddenfield>    
            </tbody>
        </table>

     
    </div>
    <div class="formBar">
        <ul>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit" onclick="return SaveSkuProduct()">
                            保存</button></div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">
                            取消</button></div>
                </div>
            </li>
        </ul>
    </div>
</div>     
<script type="text/javascript">
    function SelectItem(ct) {
//        var items = [];
//        $("input[type=checkbox][groupid]").each(function () {
//        
//            var item = {};
//            item.groupid = $(this).attr("groupid");
//            item.id = $(this).val();
//            item.isshow = $(this).is(":checked");
//            alert(item.isshow);
//            items.push(item);
//        });
        $("tr[name=skuproduct]").each(function () {

            var flage = false;
            $(this).find("td[groupid]").each(function () {
                if (!$("#cbk_" + $(this).attr("itemid")).is(":checked")) {
                    flage = true;
                }
            });
            if (flage == true) {
                $(this).css("display", "none");
            }
            else {
                $(this).css("display", "");
            }
        });
    }
    function SaveSkuProduct() {
        var skuProducts = [];
        $("tr[name=skuproduct]").each(function () {
            $this = $(this);
            var product = {};
            var items = [];
            if ($this.is(":visible")) {
                $this.find("td[groupid]").each(function () {

                    var item = {};
                    item.GroupId = $(this).attr("groupid");
                    item.GroupName = $(this).attr("groupname");
                    item.ItemId = $(this).attr("itemid");
                    item.ItemName = $(this).attr("itemname");
                    items.push(item);


                });
            product.Id = $this.attr("skuproductid");
            product.ParamCode = $.toJSON(items);
            product.MarketPrice = $this.find("input[name=txt_market_price]").first().val();
            product.SalePrice = $this.find("input[name=txt_sale_price]").first().val();
            product.Storage = $this.find("input[name=txt_storage_price]").first().val();
            product.InteriorCode = $this.find("input[name=txt_interior_code]").first().val();
            skuProducts.push(product);
            }
        });
        $("#hid_sku_pro_jsonStr").val($.toJSON(skuProducts));

        //获取已选SkuItem
        var skuItemsArr = [];
        var isPass = true;
        $("fieldset[name=fieldset_sku]").each(function () {
            $this = $(this);
            var group = {};
            var items = [];
            var flage = false;

            $this.find("input[type=checkbox]").each(function () {
                if ($(this).attr('checked') ) {
                    flage = true;
                    items.push($(this).val());
                }
            });
            //判断是否有SKU分组中没有选中任何属性
            if (flage == false) {
                alertMsg.error('发现未选SKU属性的分组,请核实是否需要该分组！如果不需要,请勿勾选该分组.');
                isPass= false;
            }
        
            group.GroupId = $this.attr("skugroupid");
            group.ItemIds = items;

            skuItemsArr.push(group);
        });
        if (!isPass) {
            return false;
        }
                    $("#hid_product_sku").val($.toJSON(skuItemsArr));
    }
</script>
</form>
